using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Business;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //UserControl uc = (UserControl)Page.LoadControl("UserControl/THU.ascx");

        GridView1.DataSource = bProduct.getAllProduct();
       // GridView1.DataSource = bPlan.getAllPlan();
        GridView1.DataBind();

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        String[] str ={ "dong oi" };
        UserControl uc = MyLoadControl("UserControl/THU.ascx", str);
        Panel1.Controls.Add(uc);
    }

    private UserControl MyLoadControl(string UserControlPath, params object[] constructorParameters)
    {
        List<Type> constParamTypes = new List<Type>();
        foreach (object constParam in constructorParameters)
        {
            constParamTypes.Add(constParam.GetType());
        }

        UserControl ctl = Page.LoadControl(UserControlPath) as UserControl;

        // Find the relevant constructor
        ConstructorInfo constructor = ctl.GetType().BaseType.GetConstructor(constParamTypes.ToArray());

        //And then call the relevant constructor
        if (constructor == null)
        {
            throw new MemberAccessException("The requested constructor was not found on : " + ctl.GetType().BaseType.ToString());
        }
        else
        {
            constructor.Invoke(ctl, constructorParameters);
        }

        // Finally return the fully initialized UC
        return ctl;
    }
}
